var printingPaperListUrl = basePath + "/sys/report/printingPaper/list";
var dataGrid;
var schoolId = $("#userSchoolId").val();

$(function() {
	initSchoolIdValue();
	loadData();
});

function loadData() {
	dataGrid = $('#notice').datagrid({
		url : printingPaperListUrl,
		toolbar: '#tb',
		fit : true,
		fitColumns : true,
		border : true,
		pagination : true,
		idField : 'id',
		pageSize : config.pageSize,
		autoRowHeight : 140,
		pageList : config.pageList,
		queryParams : {
			approvalStatus: $("#approvalStatus").val(),
			applyTimeQuery: $("#applyTimeQuery").val(),
			approvalTimeQuery: $("#approvalTimeQuery").val(),
			schoolId: schoolId
		},
		nowrap : true,
		striped : true,
		rownumbers : true,
		columns : [ [ 
			{
				field : 'id',
				align : "center",
				width : 10,
				checkbox : true
			}, 
			{ 
				field : 'depart',
				title : '部门',
				width : 10,
				resizable : true,
				align : "center"
			}, 
			{
				field : 'applyItems',
				title : '审批明细',
				width : 20,
				align : "center",
				editor:{type:'validatebox',options:{required:true}}
			},
			{
				field : 'usePosition',
				title : '使用地点',
				width : 20,
				align : "center",
				editor:{type:'validatebox',options:{required:true}}
			},
			{
				field : 'printingPaperUse',
				title : '打印纸用途',
				width : 20,
				align : "center",
				editor:{type:'validatebox',options:{required:true}}
			},
			{
				field : 'applyer',
				title : '申请人',
				width : 10,
				align : "center",
				editor:{type:'validatebox',options:{required:true}}
			},
			{
				field : 'applyTimeText',
				title : '申请时间',
				width : 15,
				align : "center"
			},
			{
				field : 'approver',
				title : '审批人',
				width : 15,
				align : "center",
				editor:{type:'validatebox',options:{required:true}}
			},
			{
				field : 'approvalTimeText',
				title : '审批时间',
				width : 15,
				align : "center"
			},
			{
				field : 'approvalStatusText',
				title : '审批状态',
				width : 10,
				align : "center"
			},
			{
				field : 'rejectReason',
				title : '驳回原因',
				width : 20,
				align : "center"
			},
			{
				field : 'remark',
				width : 20,
				title : '备注',
				align : "center"
			}

                  ] ],
		onAfterEdit : function(rowIndex, rowData, changes){
			if(rowData.id){
				changes.id = rowData.id;
				changes.resourceRange = $("#resourceRange").val();
				changes.schoolId = schoolId;
				addmodify(changes);
			}else {
				rowData.resourceRange = $("#resourceRange").val();
				rowData.schoolId = schoolId;
				addmodify(rowData);
			}
		}
	});
}

function reload() {
	dataGrid.datagrid("clearSelections");
	searchForm("searchForm");
}

function searchForm(formId) {
	dataGrid.datagrid('load', $.serializeObject($('#' + formId)));
}
function resetForm(formId) {
	$("#" + formId)[0].reset();
	$("#applyStartDate").datebox('setValue', '');
	$("#applyEndDate").datebox('setValue', '');
}
function exportToExcel(searchForm,exportUrl) {
	$("#" + searchForm).attr('action',exportUrl); 
	$("#" + searchForm).submit();  
}